#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 200005;
int n, k, ans = 0x3f3f3f3f, e_cnt, rt, tot;
int heads[N], siz[N], maxn[N], dis[N], buk[1000005], sum[N], distmp[N], sumtmp[N], cnt;
bool vis[N];

struct Edge {
  int v, nxt, w;
} e[N << 1];

inline void add(int u, int v, int w) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt, e[e_cnt].w = w;
}

void getroot(int x, int fa) {
  siz[x] = 1, maxn[x] = 0;
  for (int i = heads[x]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa || vis[v]) continue;
    getroot(v, x);
    siz[x] += siz[v];
    maxn[x] = std::max(maxn[x], siz[v]);
  }
  maxn[x] = std::max(maxn[x], tot - siz[x]);
  if (maxn[x] < maxn[rt]) rt = x;
}

void getdis(int x, int fa) {
  if (dis[x] > k) return;
  distmp[++cnt] = dis[x];
  sumtmp[cnt] = sum[x];
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if ((v = e[i].v) == fa || vis[v]) continue;
    dis[v] = dis[x] + e[i].w;
    sum[v] = sum[x] + 1;
    getdis(v, x);
  }
}

void calc(int x) {
  buk[0] = 0;
  int tmp = 0;
  cnt = 0;
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if (vis[v = e[i].v]) continue;
    dis[v] = e[i].w;
    sum[v] = 1;
    tmp = cnt;
    getdis(v, x);
    for (int j = tmp + 1; j <= cnt; ++j) {
      ans = std::min(ans, buk[k - distmp[j]] + sumtmp[j]);
    }
    for (int j = tmp + 1; j <= cnt; ++j) {
      buk[distmp[j]] = std::min(buk[distmp[j]], sumtmp[j]);
    }
  }
  for (int i = 1; i <= cnt; ++i) buk[distmp[i]] = 0x3f3f3f3f;
}

void solve(int x) {
  vis[x] = true;
  calc(x);
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if (vis[v = e[i].v]) continue;
    tot = siz[v];
    rt = 0;
    getroot(v, x);
#ifdef DEBUG
    printf("rt : %d\n", rt);
#endif
    solve(rt);
  }
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("P4149 [IOI2011]Race.in", "r", stdin);
  freopen("P4149 [IOI2011]Race.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &k);
  int u, v, w;
  for (int i = 1; i < n; ++i) {
    scanf("%d%d%d", &u, &v, &w);
    u++, v++;
    add(u, v, w);
    add(v, u, w);
  }
  maxn[rt] = 0x3f3f3f3f, tot = n;
  getroot(1, 0);
#ifdef DEBUG
  printf("rt : %d\n", rt);
#endif
  memset(buk, 0x3f, sizeof(buk));
  solve(rt);
  printf("%d", ans == 0x3f3f3f3f ? -1 : ans);
  return 0;
}